package mk.com.ldm.corepoint.implementation.shared;

import java.util.ArrayList;

import mk.com.ldm.corepoint.implementation.client.CoreService;
import mk.com.ldm.corepoint.implementation.client.CoreServiceAsync;

import org.gwt.mosaic.ui.client.MessageBox;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
 * 
 * Should send a rpc call (getMap(String type), in order to get
 * the requested object mapped, by type.
 *
 */
public class ObjectMapper {
	
	private ArrayList<?> map;
	private String type;
	CoreServiceAsync rpcService = GWT.create(CoreService.class);
	
	
	public ObjectMapper(String type){
		this.type = type;
		if(type == "simple") map = new ArrayList<SimpleObject>();
		else if(type == "config" ) map = new ArrayList<ConfigurationObject>();
		else if(type == "user") map = new ArrayList<UserObject>();
		else if(type == "permission") map = new ArrayList<PermissionsObject>();
		else if(type == "event") map = new ArrayList<EventObject>();
		else map = null; // As map type is undefined/invalid
	}
	
//	public void mapObject(String objectName, String objectType, String username){
//		rpcService.mapObject(objectName, objectType, username, new AsyncCallback<ArrayList<?>> (){
//
//			@Override
//			public void onFailure(Throwable caught) {
//				MessageBox.error("Server", "Failed to communicate with the server");
//			}
//
//			@Override
//			public void onSuccess(ArrayList<?> result) {
//				map = result;
//			}
//			
//		});
//	}
	
	
	public ArrayList<?> getMap() {
		return map;
	}

	public void setMap(ArrayList<?> map) {
		this.map = map;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}


	
}
